package com.cmnit.analysis.service

import com.cmnit.analysis.dao.GantryPlateDao
import com.cmnit.analysis.util.{ConfigurationManager, ServiceUtil}
import org.apache.log4j.Logger
import org.apache.spark.sql.DataFrame

class GantryPlateService {
  private val logger: Logger = Logger.getLogger(this.getClass)
  private val dao = new GantryPlateDao

  def service(acctTime: String): DataFrame = {
    // 获取加工账期（默认当前时间的前两小时）
    val sqlTime = ServiceUtil.getAcctInfo(acctTime)
    logger.info("加工账期时间：" + acctTime)

    // 广播门架信息码表
    dao.broadcastGantryBase().value.createOrReplaceTempView("tmp_gantry_base_info")
    logger.info("广播门架信息码表")
    dao.broadcastVehicleBase().value.createOrReplaceTempView("tmp_vehicle_base_info")
    logger.info("广播车牌-车辆类型码表")


    // 删除需要插入的账期数据
    dao.delete(ConfigurationManager.getProperty("gantryPlate.table"), ConfigurationManager.getProperty("gantryPlate.time"), acctTime)

    // 生成结果数据DataFrame
    dao.gantryPlateData(sqlTime, acctTime)
  }
}